<template>
    <h2>添加项目</h2>
<table class="table-bordered" border="1">
    <tr>
        <td>项目名称</td>
        <td><input type="text" v-model="info.I_Name"></td>
    </tr>
    <tr>
        <td>项目总金额</td>
        <td><input type="text" v-model="info.I_Budget"></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="添加" class="btn btn-success" @click="AddInvest">
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue'; 
const info=ref(
    {
        I_Name:'',
        I_Budget:''
    }
)
const AddInvest=()=>{
    if(info.value.I_Name=='')
    {
        alert('请输入项目名称')
        return;
    }
    if(info.value.I_Budget=='')
    {
        alert('请输入项目总金额')
        return;
    }
    if(isNaN(Number(info.value.I_Budget)))
    {
        alert('请输入数字')
        return;
    }
    if(Number(info.value.I_Budget)<=0)
    {
        alert('请输入大于0的数字')
        return;
    }
    axios.post('https://localhost:44382/api/Invest/AddInvest',
        {
            I_Name:info.value.I_Name,
            I_Budget:info.value.I_Budget
        }
    ).then(
        (res)=>{
            if(res.data>0)
            {
                alert('添加成功')
            }
            else
            {
                alert('添加失败')
            }
        }
    ).catch(err=>{
        console.log(err);
    })
}


</script>